<%@ page contentType="text/html;charset=UTF-8" %> 
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
	<c:if test="${warehouseShelves.editFlag == 1}">
               <title><spring:message code="warehouse_edit_create"/><spring:message code="warehouse_edit_edit"/></title>
    </c:if>
    <c:if test="${warehouseShelves.editFlag == 0 }">
               <title><spring:message code="warehouse_edit_view" /><spring:message code="warehouse_edit_ok" /></title>
    </c:if>
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
   
    <link rel="stylesheet" href="${ctxStatic}/css/common_erp.css">
    <link rel="stylesheet" href="${ctxStatic}/css/layerSm.css">
    <script src="${ctxStatic}/jquery-barcode/jquery-barcode.js" type="text/javascript"></script>
    
    
    
    <script type="text/javascript">
    
	 $(document).ready(function(){
		 var form = $("#inputForm");  
	        form.validate();//验证指定的表单
	        	$("#warehouseType").select2();
	        	if ('${warehouseShelves.editFlag == 0}') {
	       			$('.showHtml').find('input,select,textarea').attr('disabled','disabled');
				}
	     		$("#warehouseBarCodeDiv").empty().barcode($("#warehouseBarCode").val(), "code128",{barWidth:2, barHeight:30,showHRI:false}); 
	     		//$("#shelvesBarCodeTd").empty().barcode($("#shelvesBarCode").val(), "code128",{barWidth:1, barHeight:30,showHRI:false}); 
	     		var alist = document.getElementsByName("shelvesBarCodeHere");
				for (var i = 0; i < alist.length; i++) {
				 var shelvesBarCode = document.getElementsByName("shelvesBarCodeHere")[i].value;
				 $("#parentTbody div.divBar").eq(i).empty().barcode(shelvesBarCode, "code128",{barWidth:1, barHeight:30,showHRI:false}); 
				}
	        	$("#okButton").click(function(){
	        		if (form.valid()) {//如果表单验证成功，则进行提交。  
	        		$("#showHtml").addClass("showHtml");
	                $("#okHead").show();
	                $("#createHead").hide();
	                $("#operateP").hide();
	                $('tr').find('td:eq(0)').hide();
	                $('tr').children('th').eq(0).hide();	
	                $('.showHtml').find('input,radio,select,textarea').attr('disabled',true);
	                return false;
	              }
	        		
	         });
	    });
	//生成条形码 
	function barCode(){
		var alist = document.getElementsByName("shelvesBarCodeHere");
		for (var i = 0; i < alist.length; i++) {
		 var shelvesBarCode = document.getElementsByName("shelvesBarCodeHere")[i].value;
		 $("#parentTbody div.divBar").eq(i).empty().barcode(shelvesBarCode, "code128",{barWidth:1, barHeight:30,showHRI:false}); 
		}    	       	   
       }
	
	//生成仓库代码
	function whCode(){
		var warehousePlace = $("#warehousePlace").val();
		var param = {"warehousePlace":warehousePlace};
		$.post("${ctx}/warehouse/message/getWarehouseCode",param,function(result){
    		 var wCode = result["warehouseCode"];
    		 var barCode = result["warehouseBarCode"];
    		 $("#warehouseCode").val(wCode);
    		 $("#warehouseBarCode").val(barCode);
	
    	},'json');
	}
        	 
    /* 保存创建/编辑信息 */
    function editSaveForm(){
    	$('.showHtml').find('input,radio,select,textarea').attr('disabled',false);
    	getList();
    	var params = $("#inputForm").serialize();
    	$.post("${ctx}/warehouse/message/save",params,function(result){
    		/* 弹出提示框,刷新父页面,关闭当前页面 */
    		tipParent(result.message);
    		 window.parent.frames[0].searchListForm();
    		closeWin();
    		 
	
    	},'json');
    }
    
    /* 删除仓库信息 */
    function deleteWarehouse(){
    	if (confirm("<spring:message code="warehouse_areYouSure"/>")) {
    		var id = $("#id").val();
    		var param = {"id":id };
    		$.post("${ctx}/warehouse/message/delete",param,function(result){
    		/* 弹出提示框,刷新父页面,关闭当前页面 */
    		tipParent(result.message);
    		 window.parent.frames[0].searchListForm();
    	    closeWin();
				
    		},'json');
		}
    		 
	
    }
    
    /* 删除 货架  */
	 
	 function deleteCurrentRow(obj){ 
		 
		 if (confirm("<spring:message code="warehouse_shelves_areYouSure"/>")) {
           var tr=obj.parentNode.parentNode;  
           //var tbody=tr.parentNode;  
          // tbody.removeChild(tr);  
          $(tr).find("#deleteFlagHere")[0].value = 1;
          $(tr).hide();
			
		}
	 }
    function addShelvesCheck(obj){
    
	/* 获取当前行的值 */
	
    var tr = obj.parentNode.parentNode;
	var index = tr.rowIndex;
	var shelvesId = $(tr).find('input#shelvesIdList')[0].defaultValue;
    var shelvesCode = $(tr).find('input#shelvesCodeHere')[0].defaultValue;
    var shelvesName = $(tr).find('input#shelvesNameHere')[0].defaultValue;
    var shelvesBarCode = $(tr).find('input#shelvesBarCodeHere')[0].defaultValue;
    var shelvesPlace = $(tr).find('input#shelvesPlaceHere')[0].defaultValue;
    var shelvesStatus = $(tr).find('input#shelvesStatusHere')[0].defaultValue;
    var shelvesRemark = $(tr).find('input#shelvesRemarkHere')[0].defaultValue;
	var firstName = $("#firstName").val();
	popup('500px','324px','${ctx}/warehouse/message/addShelves?shelvesId='+shelvesId+'&shelvesCode='+shelvesCode+'&shelvesName='+shelvesName+'&shelvesBarCode='+shelvesBarCode+'&shelvesPlace='+shelvesPlace+'&shelvesStatus='+shelvesStatus+'&shelvesRemark='+shelvesRemark+'&index='+index+'&firstName='+firstName);
	
    }
    	
    function getList() {
    	var shelvesId = document.getElementsByName("shelvesIdList");
    	var shelvesCode = document.getElementsByName("shelvesCodeHere");
		var shelvesBarCode = document.getElementsByName("shelvesBarCodeHere");
    	var shelvesName = document.getElementsByName("shelvesNameHere");
    	var shelvesPlace = document.getElementsByName("shelvesPlaceHere");
		var shelvesStatus = document.getElementsByName("shelvesStatusHere");
		var deleteFlag = document.getElementsByName("deleteFlagHere");
    	var shelvesRemark = document.getElementsByName("shelvesRemarkHere");
    	var createShelvesDate = document.getElementsByName("createShelvesDateHere");
    	var createShelvesUser = document.getElementsByName("createShelvesUserHere");    	
    	var hiddenHtml = "";
		for (var i = 0; i < shelvesName.length; i++) {
			hiddenHtml+= "<input type='hidden' name='warehouseShelvesList["+i+"].shelvesId' value='"+shelvesId[i].value+"'><input type='hidden' name='warehouseShelvesList["+i+"].deleteFlag' value='"+deleteFlag[i].value+"'><input type='hidden' name='warehouseShelvesList["+i+"].shelvesCode' value='"+shelvesCode[i].value+"'><input type='hidden' name='warehouseShelvesList["+i+"].shelvesBarCode' value='"+shelvesBarCode[i].value+"'><input type='hidden' name='warehouseShelvesList["+i+"].shelvesName' value='"+shelvesName[i].value+"'><input type='hidden' name='warehouseShelvesList["+i+"].shelvesPlace' value='"+shelvesPlace[i].value+"'><input type='hidden' name='warehouseShelvesList["+i+"].shelvesStatus' value='"+shelvesStatus[i].value+"'><input type='hidden' name='warehouseShelvesList["+i+"].shelvesRemark' value='"+shelvesRemark[i].value+"'><input type='hidden' name='warehouseShelvesList["+i+"].createShelvesDate' value='"+createShelvesDate[i].value+"'><input type='hidden' name='warehouseShelvesList["+i+"].createShelvesUser' value='"+createShelvesUser[i].value+"'>";
		}
		$("#hiddenHtml").html(hiddenHtml);
	}	
    </script>
    <style type="text/css">
    					.table-ckhjcz{width: 65px;}
    					.table-ckhjbm{width: 115px;}
                        .table-ckhjtxm{width: 135px;}
                        .table-ckhjmc{width: 100px;}
                        .table-ckhjwz{width: 80px;}
                        .table-ckhjzt{width: 60px;}
                        .table-ckhjms{width: 90px;}
                        .table-ckhjcjr{width: 80px;}
                        .table-ckhjcjsj{width: 70px;}
    </style>
</head>
<body>   
<form id="inputForm" name="inputForm">
<!-- 创建编辑头部 -->
<c:if test="${warehouseShelves.editFlag == 1}">
<div id="createHead" class="layerHeader clearfix">
	<c:choose>
	   <c:when test="${warehouseShelves.id!=null && warehouseShelves.id!=''}">
	    <!-- 编辑 --> 
			<p class="headerTitle"><spring:message code="warehouse_edit_edit"/></p>
       </c:when>
       <c:otherwise>
        <!-- 创建 --> 
            <p class="headerTitle"><spring:message code="warehouse_edit_create"/></p>
       </c:otherwise>
    </c:choose>
    <div class="headerButton clearfix">
        <!-- 确认 -->      
       	<button type="button" id="okButton" ><spring:message code="warehouse_edit_ok"/></button>
        <!-- 取消 -->
        <button type="button" onclick="closeWin()"><spring:message code="warehouse_edit_cancle"/></button>
    </div>
</div>
<!-- 确认画面头部 -->
<div id="okHead" class="layerHeader clearfix" style="display: none;">	      
             <p class="headerTitle"><spring:message code="warehouse_edit_ok" /></p>    
    <div class="headerButton clearfix">
    <c:choose>
	   <c:when test="${warehouseShelves.id!=null && warehouseShelves.id!=''}">
	    <!-- 编辑 保存 --> 
	    <shiro:hasPermission name="warehouse:message:edit">
			<button type="button" onclick="editSaveForm()"><spring:message code="common_save" /></button>
			</shiro:hasPermission>
       </c:when>
       <c:otherwise>
        <!-- 创建 保存 --> 
        <shiro:hasPermission name="warehouse:message:edit">
            <button type="button" onclick="editSaveForm()"><spring:message code="common_save" /></button>
            </shiro:hasPermission>
       </c:otherwise>
     </c:choose>
        
          
        <!-- 取消 -->
          <button type="button" onclick="closeWin()"><spring:message code="warehouse_edit_cancle"/></button>
    </div>
</div>
</c:if>
 <!-- 查看画面头部 -->
<c:if test="${warehouseShelves.editFlag == 0}">
<div id="viewHead" class="layerHeader clearfix" >
          <p class="headerTitle"><spring:message code="warehouse_edit_view" /></p>
    <div class="headerButton clearfix">
        <!-- 编辑 -->
        <shiro:hasPermission name="warehouse:message:view">
          <button type="button" onclick="popup('800px','519px','${ctx}/warehouse/message/editWarehouse?id=${warehouseShelves.id}&editFlag=1');closeWin()">
               	<spring:message code="warehouse_edit_edit" />
          </button>
          </shiro:hasPermission>
        <!-- 删除  -->
        <shiro:hasPermission name="warehouse:message:edit">
          <button type="button" onclick="deleteWarehouse();">
               	<spring:message code="warehouse_edit_delete" />
          </button>
          </shiro:hasPermission>
        <!-- 取消 -->
          <button type="button" onclick="closeWin()"><spring:message code="warehouse_edit_cancle"/></button>
    </div>
</div>
</c:if>

<!-- 入力框 -->
<div style="overflow-y: auto;height: 500px;">
<div id="showHtml" class="tabBoxSm <c:if test="${warehouseShelves.editFlag == 0}">showHtml</c:if>" >
    <div class="tabSm smOrderBox">
        <div class="clearfix">
        <input type="hidden" id="id" name="id" value="${warehouseShelves.id}">
    	<input type="hidden" id="createDate" name="createDate" value="${fns:getDate('yyyy-MM-dd HH:mm')}">
        <input type="hidden" id="editFlag" name="editFlag" value="${warehouseShelves.editFlag}">
        	<div class="left w-350">
        	
        	<c:if test="${warehouseShelves.id!=null && warehouseShelves.id!=''}">
        	   <!--  公司编号 -->
            	<div class="items clearfix">
                	<p class="tit"><spring:message code="warehouse_code"/></p>
                    <input id="warehouseCode" name="warehouseCode" style="border: none;color: #333;background-color: inherit;" disabled="true" value="${warehouseShelves.warehouseCode}" >
                    
                </div>
              </c:if>
                
                
                <div class="items clearfix haveToBox">
                <c:set value="WAREHOUSE_CATEGORY" var="warehouseCategory" />
                
                	<!--  仓库类型  -->
                	<p class="tit"><spring:message code="warehouse_type"/></p>
                	<select id="warehouseType" name="warehouseType" style="width: 150px" data-rule-required="true" data-msg-required="<spring:message code="warehouse_edit_err_msg_warehouseType"/>">
					<option value=""><spring:message code="company_edit_pleaseChoose"/></option>
					<c:forEach items="${fns:getDictList(warehouseCategory)}" var="warehouse">
                        <option  value="${warehouse.itemCode}-${warehouse.itemValue}" <c:if test="${warehouseShelves.warehouseTypeCn eq warehouse.itemName }">selected="selected"</c:if>>${warehouse.itemName}</option>
                    </c:forEach>
                    </select>
                    <p class="haveTo">*</p>
                </div>
               <!--  仓库名称 -->
                <div class="items clearfix haveToBox">
                	<p class="tit"><spring:message code="warehouse_name"/></p>
                    <input id="warehouseName" name="warehouseName" maxlength="50" value="${warehouseShelves.warehouseName}" data-rule-required="true" data-msg-required="<spring:message code="warehouse_edit_err_msg_warehouseName"/>">
                    <p class="haveTo">*</p>
                </div>
     
            </div>
            <div class="right">
        			<input type="hidden" id="warehouseBarCode" name="warehouseBarCode" value="${warehouseShelves.warehouseBarCode}"> 
            <c:if test="${warehouseShelves.id!=null && warehouseShelves.id!=''}">
            	<!-- 仓库条形码 -->
            	<div class="items clearfix">
                	<p class="tit"><spring:message code="warehouse_barCode"/></p>
                	<div id="warehouseBarCodeDiv"></div>
                </div>
                </c:if>
                <!--  仓库位置 -->
                <div class="items clearfix haveToBox">
                	<p class="tit"><spring:message code="warehouse_place"/></p>
                    <input id="warehousePlace" name="warehousePlace" style="ime-mode: disabled;" onchange="whCode()" maxlength="6" data-rule-required="true" data-msg-required="<spring:message code="warehouse_edit_err_msg_warehousePlace"/>" value="${warehouseShelves.warehousePlace}" >
                    <p class="haveTo">*</p>
                </div>
                 <!--  仓库代码 -->
                <div class="items clearfix haveToBox">
                	<p class="tit"><spring:message code="warehouse_code"/></p>
                    <input id="warehouseCode" name="warehouseCode" maxlength="50" value="${warehouseShelves.warehouseCode}" >
                    <p class="haveTo">*</p>
                </div>
               
            </div>
       
        </div> 
	</div>
    
	<!-- 仓库货架 -->
	
	
			<div style="width:790px;height: 20px;padding: 0 10px;">
				<div style="float: left;">
				<p class="tit"><spring:message code="warehouse_create_shelves"/></p>
				</div>
				<div style="float: right;">
				<c:if test="${warehouseShelves.editFlag == 1}">
				<a href="###" id="operateP" onclick="popup('500px','324px','${ctx}/warehouse/message/addShelves')"><spring:message code="warehouse_create_addShelves"/></a>
				</c:if>   
				</div>
			</div>
    <div class="tableArea">
    	<div class="tableScrollSm" style="overflow-y: auto;height: 160px;width: 787px;border: 1px">
        	<!-- <div class="" style="overflow-y: auto;height: 150px;width: 780px;border: 1px"> -->
        		<table cellpadding="0" class="tableHead" style="z-index: 9999;width: 770px" >
                    <thead>
                    <tr>
                     <c:if test="${warehouseShelves.editFlag == 1}">
                    	<th id="operateTh" class="table-ckhjcz"><spring:message code="warehouse_shelves_operate"/></th>
                     </c:if>    
                        <th class="table-ckhjbm"><spring:message code="warehouse_shelves_code"/></th>
                        <th class="table-ckhjtxm"><div style="padding: 0px; overflow: auto; width: 121px;"><spring:message code="warehouse_shelves_barCode"/></div></th>
                        <th class="table-ckhjmc"><spring:message code="warehouse_shelves_name"/></th>
                        <th class="table-ckhjwz"><spring:message code="warehouse_shelves_place"/></th>
                        <th class="table-ckhjzt"><spring:message code="warehouse_shelves_status"/></th>
                        <th class="table-ckhjms"><spring:message code="warehouse_shelves_remark"/></th>
                        <th class="table-ckhjcjr"><spring:message code="warehouse_shelves_creator"/></th>
                        <th class="table-ckhjcjsj"><spring:message code="warehouse_shelves_createDate"/></th>
                    </tr>
                    <thead>
                </table>
        		<table cellpadding="0" class="tableBody" style="width: 770px">
                    <tbody id="parentTbody">
         		<c:forEach items="${warehouseShelves.warehouseShelvesList}" var="shelves" varStatus="status">
				  <c:if test="${not empty shelves}">
                    <tr>
                     <c:if test="${warehouseShelves.editFlag == 1}">
                    	<td class="table-ckhjcz"><img src="${ctxStatic}/images/btn-bj.png" onclick="addShelvesCheck(this)" height="25" width="25">&nbsp;<img src="${ctxStatic}/images/btn-sc.png" height="25" width="25"  onclick="deleteCurrentRow(this)"></td>
                     </c:if>   
                        <td class="table-ckhjbm">${shelves.shelvesCode }</td>
                        <td class="table-ckhjtxm" align="center"><div class="divBar"></div></td>
                        <td class="table-ckhjmc">${shelves.shelvesName }</td>
                        <td class="table-ckhjwz">${shelves.shelvesPlace }</td>
                        <td class="table-ckhjzt"><c:if test="${shelves.shelvesStatus==1}"><spring:message code="warehouse_shelves_open"/></c:if><c:if test="${shelves.shelvesStatus==0}"><spring:message code="warehouse_shelves_close"/></c:if></td>
                        <td class="table-ckhjms">${shelves.shelvesRemark }</td>
                        <td class="table-ckhjcjr">${shelves.createBy.firstName }</td>
                        <td class="table-ckhjcjsj" ><fmt:formatDate value="${shelves.createShelvesDateDB }" pattern="yyyy-MM-dd" /></td>                       
                        <input type="hidden" id="shelvesIdList" name="shelvesIdList" value="${shelves.shelvesId }">
                        <input type="hidden" id="shelvesCodeHere" name="shelvesCodeHere" value="${shelves.shelvesCode }">
                        <input type="hidden" id="shelvesBarCodeHere" name="shelvesBarCodeHere" value="${shelves.shelvesBarCode }">
                        <input type="hidden" id="shelvesNameHere" name="shelvesNameHere" value="${shelves.shelvesName }">
                        <input type="hidden" id="shelvesPlaceHere" name="shelvesPlaceHere" value="${shelves.shelvesPlace }">
                        <input type="hidden" id="shelvesStatusHere" name="shelvesStatusHere" value="${shelves.shelvesStatus }">
                        <input type="hidden" id="deleteFlagHere" name="deleteFlagHere" value="${shelves.deleteFlag }">
                        <input type="hidden" id="shelvesRemarkHere" name="shelvesRemarkHere" value="${shelves.shelvesRemark }">
                        <input type="hidden" id="createShelvesDateHere" name="createShelvesDateHere" value="${shelves.createShelvesDate }">
                        <input type="hidden" id="createShelvesUserHere" name="createShelvesUserHere" value="${shelves.createShelvesUser }">
                    </tr>
                  </c:if>
                </c:forEach>
                	</tbody>
                </table>
                <div id="hiddenHtml"></div>
            </div>
        </div>
	<div class="smOrderBox" style="padding: 0px 20px">
	<div class="items clearfix">
                	<p class="tit"><spring:message code="warehouse_create_status"/></p>
                				<c:if test="${warehouseShelves.editFlag == 1}">
                                    <div class="labelBox">
                                    <label>
                                        <input type="radio" style="width:20px;" id="yes" name="warehouseStatus" value="1"  <c:if test="${warehouseShelves.warehouseStatus eq 1 ||warehouseShelves.warehouseStatus eq null}"> checked="checked"</c:if>>
                                        <spring:message code="warehouse_create_open"/>
                                       </label>
                                       <label>
                                        <input type="radio" style="width:20px;" id="no" name="warehouseStatus" value="0"  <c:if test="${warehouseShelves.warehouseStatus eq 0}"> checked="checked"</c:if>>
                                        <spring:message code="warehouse_create_close"/>
                                   		</label>
                                   		</div>
                                   	</c:if>
                    <c:if test="${warehouseShelves.editFlag == 0}">
                    	<c:if test="${warehouseShelves.warehouseStatus eq 1}">
                    		<p class="tit"><spring:message code="warehouse_create_open"/></p>
                    	</c:if>
                   		<c:if test="${warehouseShelves.warehouseStatus eq 0}">
                    		<p class="tit"><spring:message code="warehouse_create_close"/></p>
                    	</c:if>
                    </c:if>
                                  
                                  
                </div>
	
			<!--  备注 -->
               <div class="items clearfix">
                	<p class="tit"><spring:message code="warehouse_remark"/></p>
                    <textarea id="warehouseRemark" name="warehouseRemark" style="width: 300px;height: 100px;">${warehouseShelves.warehouseRemark}</textarea>
                </div>



	</div>
</div>
</div>  
</form>
<script>
</script>
</body>
</html>
